package com.sip.stream.utils.zfy.osd;

import android.util.Log;
import com.gosuncn.zfyluancher.ZFYLauncherJNI;
import com.sip.stream.utils.zfy.config.ZFYOSDConfig;

import java.util.Arrays;
import java.util.Iterator;

public class OSDInvertTimerTool extends AbstractYUVOSDTool {
    public OSDInvertTimerTool(int width, int height, ZFYOSDConfig zFYOSDConfig) {
        super(width, height, zFYOSDConfig);
        TAG = "OSDInvertTimerTool";
    }

    @Override
    protected void addOSDToI420Jni(byte[] bArr, OSDBean oSDBean) {
        ZFYLauncherJNI.addOSDToI420HZK(bArr, this.cacheSrcWidth, this.cacheSrcHeight, oSDBean.getDarkData(), oSDBean.getOsdwidth(), oSDBean.getOsdheight(), oSDBean.getStartX(), oSDBean.getStartY(), this.cacheScale);
        ZFYLauncherJNI.addOSDToI420HZKBlack(bArr, this.cacheSrcWidth, this.cacheSrcHeight, oSDBean.getLightData(), oSDBean.getOsdwidth(), oSDBean.getOsdheight(), oSDBean.getStartX(), oSDBean.getStartY(), this.cacheScale);
    }

    @Override
    protected void addOSDToI420ASCII(byte[] bArr, OSDBean oSDBean) {
        int startX = oSDBean.getStartX();
        if (startX < 0) {
            startX = (this.cacheSrcWidth - 15) - ((this.cacheScale * 8) * oSDBean.getDarkData().length);
        }
        int i = startX;
        ZFYLauncherJNI.addOSDToI420HZK(bArr, this.cacheSrcWidth, this.cacheSrcHeight, oSDBean.getDarkData(), oSDBean.getDarkData().length / 16, 16, i, oSDBean.getStartY(), this.cacheScale);
        ZFYLauncherJNI.addOSDToI420HZKBlack(bArr, this.cacheSrcWidth, this.cacheSrcHeight, oSDBean.getLightData(), oSDBean.getDarkData().length / 16, 16, i, oSDBean.getStartY(), this.cacheScale);
    }

    @Override
    protected void setupDynamicOSD(byte[] bArr, String str) {
        Iterator<OSDBean> it = this.staticOSDBeans.iterator();
        while (it.hasNext()) {
            OSDBean next = it.next();
            byte[] darkData = next.getDarkData();
            if (darkData == null) {
                darkData = new byte[next.getOsdData().length];
                next.setDarkData(darkData);
            }
            byte[] bArr2 = darkData;
            Arrays.fill(bArr2, (byte) 0);
            byte[] lightData = next.getLightData();
            if (lightData == null) {
                lightData = new byte[next.getOsdData().length];
                next.setLightData(lightData);
            }
            byte[] bArr3 = lightData;
            Arrays.fill(bArr3, (byte) 0);
            ZFYLauncherJNI.calcInvertPart(bArr, this.cacheSrcWidth, this.cacheSrcHeight, next.getOsdData(), next.getOsdwidth(), next.getOsdheight(), bArr3, bArr2, next.getStartX(), next.getStartY(), this.cacheScale);
        }
        Iterator<OSDBean> it2 = this.dynamicOSDBeans.iterator();
        while (it2.hasNext()) {
            OSDBean next2 = it2.next();
            byte[] dynamicOSD = getDynamicOSD(next2, str);
            byte[] bArr4 = new byte[dynamicOSD.length * 16];
            Arrays.fill(bArr4, (byte) 0);
            next2.setDarkData(bArr4);
            byte[] bArr5 = new byte[dynamicOSD.length * 16];
            Arrays.fill(bArr5, (byte) 0);
            next2.setLightData(bArr5);
            Arrays.fill(bArr5, (byte) 0);
            ZFYLauncherJNI.calcInvertASCIIPart(bArr, this.cacheSrcWidth, this.cacheSrcHeight, dynamicOSD, dynamicOSD.length, 16, bArr5, bArr4, next2.getStartX(), next2.getStartY(), this.cacheScale);
        }
        Log.i(TAG, "setup End");
    }
}
